/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fjnu.bll;

import fjnu.dao.AbstractObject;
import fjnu.dao.Lamp;
import fjnu.dao.factory.Factory;
import fjnu.dao.factory.AbstractMapper;
import fjnu.dao.mysql.MysqlFactory;

/**
 *
 * @author neco
 */
public class LookUp {

    private AbstractMapper am;
    private Factory af;

    public LookUp()
    {
        af=new MysqlFactory();
    }
    public AbstractObject findObjectByID(int ID, int Type) {
        AbstractObject ao = this.QueryObjecyInCache(ID);
        if (ao == null) {
            switch (Type) {
                case 01:
                    am = af.getLampMapper();                    
                    break;
                case 02:
                    am = af.getTrashMapper();
                    break;
                case 03:
                     am = af.getGuidePostMapper();
                    break;
                case 04:
                    am = af.getBulletinBoardMapper();
                    break;
                case 05:
                    am = af.getSportSequipmentMapper();
                    break;
                default:
                    return ao;
            }
             ao = am.getObjectByID(ID);
        }
       
        return ao;
    }

    public AbstractObject findObjectByIDNotCache(int ID, int Type) {
        AbstractObject ao=null;
            switch (Type) {
                case 01:
                    am = af.getLampMapper();                    
                    break;
                case 02:
                    am = af.getTrashMapper();
                    break;
                case 03:
                     am = af.getGuidePostMapper();
                    break;
                case 04:
                    am = af.getBulletinBoardMapper();
                    break;
                case 05:
                    am = af.getSportSequipmentMapper();
                    break;
                default:
                    return ao;
            }
             ao = am.getObjectByIDNotCache(ID);       
        return ao;
    }
    private AbstractObject QueryObjecyInCache(int ID) {
        return Cache.getInstance().getObjectByID(ID);
    }
}
